function addVenue(venueId) {
    var array = venueId.split("_");
    venueCounter = parseInt(array[1]) + 1;
    $(".tabBox ul li").removeClass('active');
    $(".venueContent").hide();
   $(".tabBox ul li").eq(-2).append('<li class="active add_venue_course_show_hide_' + venueCounter + '"><a href="javascript:void(0)" id="venue_course_show_hide_' + venueCounter + '" onclick="showVenueContent(this.id);"> Venue <span class="createdVenueCount" id="create_venue_course_show_hide_' + venueCounter + '"> 1 </span> </a><a href="javascript:void(0)" class="close-btn venue-first" id="venue_remove_' + venueCounter + '" onclick="reMoveVenue(this.id);"></a></li>');
    createdVenueCount();
    $(".venueDetails").append('<div id="venue_count_' + venueCounter + '" class="venue_course_show_hide_' + venueCounter + ' venueContent">\n\
<div class="row"><div class="col-lg-4 col-md-4 col-sm-4 column4"><input type="hidden" name="venueIndex[]" value ="' + venueCounter + '">\n\
<label for="class_venue_venueid_">Select Venue</label><span style="display:none;">' + getVenueName('course_venue_venueid_' + venueCounter + '') + '</span><select name="ClassVenue[venueId][]" id="course_venue_venueid_' + venueCounter + '"  onchange="getVanueDeatils(this.id);", class="form-control book-control selectedVenue"></select> <span class="class-arrow1"></span>\n\
<p id="error_course_venue_venueid_' + venueCounter + '" class="errorMessage" style="display:none">You have already select this venue.so please select another venue!</p>\n\
</div><div class="col-lg-8 col-md-8 col-sm-8 course-pdr column8"><label for="ClassVenue_name">Name<span class="required">*</span></label>\n\
<input maxlength="45" name="ClassVenue[name][]" id="course_venue_name_' + venueCounter + '" type="text" class="requiredfield  form-control book-control" onblur="checkValueEmpty(this.id)">\n\
<div class="error<Message" id="error_course_venue_name_' + venueCounter + '" style="display:none">Name cannot be blank.</div></div></div><div class="col-lg-12 col-md-12 column12 course-pdr">\n\
<label for="ClassVenue_address_line1">Address Line1<span class="required">*</span></label><input maxlength="45" name="ClassVenue[address_line1][]" id="course_venue_address_line1_' + venueCounter + '" type="text" class="requiredfield form-control book-control" onblur="checkValueEmpty(this.id)">\n\
<div class="errorMessage" id="error_course_venue_address_line1_' + venueCounter + '" style="display:none">Address Line1 cannot be blank.</div></div>\n\
 <div class="col-lg-12 col-md-12 column12 course-pdr"><label for="ClassVenue_address_line2">Address Line2</label><input maxlength="45" name="ClassVenue[address_line2][]" id="course_venue_address_line2_' + venueCounter + '" type="text" class="form-control book-control"></div>\n\
<div class="col-lg-12 col-md-12 column12 course-pdr"><label for="ClassVenue_venue_locality">Locality<span class="required">*</span></label>\n\
<input maxlength="45" name="ClassVenue[venue_locality][]" id="course_venue_venue_locality_' + venueCounter + '" type="text" class="form-control book-control" onkeyup="getLocality(this.id)" onpaste="return false;">\n\
<div class="errorMessage" id="error_course_venue_venue_locality_' + venueCounter + '" style="display:none">Locality cannot be blank.</div>  <div class="errorMessage" id="error_local_course_venue_venue_locality_' + venueCounter + '"></div></div>\n\
<div class="clearfix"><div class="col-lg-4 col-md-4 col-sm-4 column4 "><label for="ClassVenue_zip_code">Zip Code<span class="required">*</span></label><input maxlength="6" name="ClassVenue[zip_code][]" id="course_venue_zip_code_' + venueCounter + '" type="text" class="requiredfield form-control book-control" onblur="checkValueEmpty(this.id)">\n\
<div class="errorMessage" id="error_course_venue_zip_code_' + venueCounter + '" style="display:none">Zip code cannot be blank.</div></div>\n\
<div class="col-lg-8 col-md-8 col-sm-8 course-pdr column8"><label for="ClassVenue_country_id" class="required">Country Name<span class="required">*</span></label>\n\
<span style="display:none;">' + getAllCountry('course_venue_country_id_' + venueCounter + '') + '</span><select name="ClassVenue[country_id][]" id="course_venue_country_id_' + venueCounter + '" onchange="getSelectedState(this.id)" class="form-control book-control"></select><span class="class-arrow1"></span>\n\
<div class="errorMessage" id="error_course_venue_country_id_' + venueCounter + '" style="display:none">Country Name  cannot be blank.</div></div></div><div class="clearfix">\n\
<div class="col-lg-4 col-md-4 col-sm-4 column4"><label for="ClassVenue_state_id" class="required">State Name<span class="required">*</span></label>\n\
<select class="form-control book-control" name="ClassVenue[state_id][]" id="course_venue_state_id_' + venueCounter + '"  onchange="getSelectedCity(this.id)"></select>\n\
<div class="errorMessage" id="error_course_venue_state_id_' + venueCounter + '" style="display:none">State Name  cannot be blank.</div></div>\n\
<div class="col-lg-8 col-md-8 col-sm-8 course-pdr column8"><label for="ClassVenue_city_id" class="required">City Name<span class="required">*</span></label>\n\
<select class="form-control book-control" name="ClassVenue[city_id][]" id="course_venue_city_id_' + venueCounter + '"></select><span class="class-arrow1"></span>\n\
<div class="errorMessage" id="error_course_venue_city_id_' + venueCounter + '" style="display:none">City Name  cannot be blank.</div></div></div> <div class="row"> <div class="clearfix"></div>\n\
<div class="addbatch_venue_' + venueCounter + '_batch"><div class="venue_count' + venueCounter + '_batch_0"><div class="batch-second">\n\
<div class="details-collapse clearfix" id="venue_count' + venueCounter + '_batchShowToggle_0" onclick="showhideBatch(this.id);"><h3><span>batch <span class="createdVenueBatchCount create_venue_' + venueCounter + '_batchcounter" id="create_venue_' + venueCounter + '_batch_counter_0">1</span><span class="buttom-exp pull-right"><em class="sprite dw-arrow"></em></span>\n\
</h3></div> <div class="clearfix contenttoggleClass venue_count' + venueCounter + '_batchShowToggle_0"><div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3">\n\
 <label for="CourseBatche_date_from" class="required">Start Date<span class="required">*</span></label> <input type="hidden" name="batchIndex[' + venueCounter + '][]" value="0">\n\
<input id="course_venue_' + venueCounter + '_batch_start_date_0" name="CourseBatche[ClassVenue][' + venueCounter + '][date_from][]" type="text" class="requiredfield hasDatepicker span2 form-control book-control" onkeyup="hasDatepicker(this.id);"  onblur="checkValueEmpty(this.id)" onclick="hasDatepicker(this.id);" onpaste="return false;" onchange="checkDate(this.id)">\n\
<div class="errorMessage" id="error_course_venue_' + venueCounter + '_batch_start_date_0" style="display:none">Start date cannot be blank.</div></div> <div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3">\n\
<label for="CourseBatche_date_to" class="required">End Date <span class="required">*</span></label><input name="CourseBatche[ClassVenue][' + venueCounter + '][date_to][]" id="course_venue_' + venueCounter + '_batch_end_date_0" type="text" class="hasDatepicker requiredfield span2 form-control book-control" onkeyup="hasDatepicker(this.id)" onclick="hasDatepicker(this.id)" onpaste="return false;" onblur="checkValueEmpty(this.id)" onchange="checkDate(this.id)">\n\
<div class="errorMessage" id="error_course_venue_' + venueCounter + '_batch_end_date_0" style="display:none">End date cannot be blank.</div>\n\
<div class="errorMessage" id="enddate_course_venue_' + venueCounter + '_batch_end_date_0"></div></div><div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3">\n\
 <label for="CourseBatche_price" class="required">Price <span class="required">*</span></label>\n\
<input  name="CourseBatche[ClassVenue][' + venueCounter + '][price][]" id="course_venue_' + venueCounter + '_batch_price_0" type="text" onkeypress="return isNumberKey(event)" class="requiredfield span2 form-control book-control" onblur="checkValueEmpty(this.id)">\n\
<div class="errorMessage" id="error_course_venue_' + venueCounter + '_batch_price_0" style="display:none">Price cannot be blank.</div></div>\n\
 <div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3"><label for="CourseBatche_seats" class="required">Seats <span class="required">*</span></label>\n\
<input  name="CourseBatche[ClassVenue][' + venueCounter + '][seats][]" id="course_venue_' + venueCounter + '_batch_seats_0" type="text" onkeypress="return isNumberKey(event)" class="requiredfield span2 form-control book-control"" onblur="checkValueEmpty(this.id)">\n\
<div class="errorMessage" id="error_course_venue_' + venueCounter + '_batch_seats_0" style="display:none">Seats cannot be blank.</div>\n\
</div><div class="batch-disc">  <h4>Batch discounts:</h4><div id="venue_' + venueCounter + '_batch_0_earlydiscount"></div> <div class="form-group">\n\
<div class="col-lg-3 col-md-3 col-sm-3 column3 add-disc course-pdl"><a href="javascript:void(0)" id="venue_' + venueCounter + '_batch_0_earlydiscount_0" onclick="addEarlyDiscount(this.id);">+ Add Early Discounts</a> </div> </div>\n\
<div id="venue_' + venueCounter + '_batch_0_groupdiscount"></div><div class="form-group"><div class="col-lg-3 col-md-3 col-sm-3 column3 add-disc course-pdl">\n\
<a href="javascript:void(0)" id="venue_' + venueCounter + '_batch_0_groupdiscount_0" onclick="addGroupDiscount(this.id);">+ Add Group Discounts</a></div> </div>\n\
<div class="row"><div class="col-lg-12 col-md-12 col-sm-12 course-pdl column12"><div class="my-radio"><input type="radio" class="venue_' + venueCounter + '_batch_0_fancyRadio" id="venue_' + venueCounter + '_batch_0_daySession_show_hide" name="days_venue_' + venueCounter + '_batch_0" checked="checked" onclick="showDateSessionAndDaySesion(this.id)"><label for="venue_' + venueCounter + '_batch_0_daySession_show_hide">Days of the week</label>\n\
<input type="radio" class="venue_' + venueCounter + '_batch_0_fancyRadio" id="venue_' + venueCounter + '_batch_0_dateSession" name="days_venue_' + venueCounter + '_batch_0" onclick="showDateSessionAndDaySesion(this.id)"><label for="venue_' + venueCounter + '_batch_0_dateSession" >Number of Sessions</label>\n\
</div></div></div></div> <div class="batch-disc"><h4>Batch Session:</h4><div class="venue_' + venueCounter + '_batch_0_daySession_show_hide">\n\
<div class="form-group"> <div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3"> <label for="course_venue_0_batch_0_daySession_schedule_id_0">Select day</label>\n\
<span class="class-arrow12"></span><select name="CourseBatcheDaySession[CourseBatche][0][ClassVenue][' + venueCounter + '][schedule_id][]" id="course_venue_' + venueCounter + '_batch_0_daySession_schedule_id_0" class="requiredfield form-control book-control">\n\
<option value="">Select Day</option><option value="5">Monday</option><option value="6">Tuesday</option><option value="7">Wednesday</option>\n\<option value="8">Thursday</option><option value="9">Friday</option><option value="10">Saturday</option><option value="11">Sunday</option></select>\n\
<div class="errorMessage" id="error_course_venue_' + venueCounter + '_batch_0_daySession_schedule_id_0" style="display:none">Schedule cannot be blank.</div></div>\n\
<div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3"><label for="b-stime">Start time:</label><div class="input-append bootstrap-timepicker time-sin">\n\
<input  name="CourseBatcheDaySession[CourseBatche][0][ClassVenue][' + venueCounter + '][time_from][]" id="course_venue_' + venueCounter + '_batch_0_daySession_time_from_0" type="text"  class="hastimePicker requiredfield  add-on book-control time-sin" onclick="hastimePicker(this.id)" onpaste="return false;" onblur="checkValueEmpty(this.id)" onchange="timeCheck(this.id);"> \n\
<div class="errorMessage" id="error_course_venue_' + venueCounter + '_batch_0_daySession_time_from_0" style="display:none">Start time cannot be blank.</div> </div> </div>\n\
<div class="col-lg-6 col-md-6 col-sm-6 course-pdr column6"><div class="col-lg-7 col-md-7 col-sm-7 column6"><label for="b-etime">End time:</label><div class="input-append bootstrap-timepicker time-sin">\n\
<input name="CourseBatcheDaySession[CourseBatche][0][ClassVenue][' + venueCounter + '][time_to][]" id="course_venue_' + venueCounter + '_batch_0_daySession_time_to_0" class="hastimePicker requiredfield  add-on book-control time-sin" onclick="hastimePicker(this.id)" onpaste="return false;" onblur="checkValueEmpty(this.id)" type="text"   size="10" onchange="timeCheck(this.id);">\n\
<div class="errorMessage" id="error_course_venue_' + venueCounter + '_batch_0_daySession_time_to_0" style="display:none">End time cannot be blank.</div>\n\
 <div class="errorMessage" id="endTime_course_venue_' + venueCounter + '_batch_0_daySession_time_to_0" ></div></div></div><div class="col-lg-5 col-md-5 col-sm-5 column5">\n\
<div class="batch-flexible"><input type="checkbox" class="fancyCheckBox" value="1" id="course_venue_' + venueCounter + '_batch_0_daySession_is_flexible_0" onclick="datedaySesionisFlexble(this.id)" name="CourseBatcheDaySessions[CourseBatche][0][ClassVenue][' + venueCounter + '][is_flexible][]" >\n\
<label for="course_venue_' + venueCounter + '_batch_0_daySession_is_flexible_0"> Flexible </label><input type="hidden" name="CourseBatcheDaySession[CourseBatche][0][ClassVenue][' + venueCounter + '][is_flexiblevalue][]" value="0" id="course_venue_' + venueCounter + '_batch_0_daySession_is_flexiblevalue_0"/>\n\
</div> </div> </div> </div> </div> <div class="venue_' + venueCounter + '_batch_0_daySession"></div><div class="venue_' + venueCounter + '_batch_0_daySession_addSesion">\n\
 <div class="form-group"><div class="col-lg-3 col-md-3 col-sm-3 add-disc course-pdl column3"><a  href="javascript:void(0);" onclick="addDaySession(this.id);" id="venue_' + venueCounter + '_batch_0_daySession_0">+Add More</a>\n\
</div></div></div><div class="form-group  venue_' + venueCounter + '_batch_0_dateNoSession" style="display: none;"> <div class="row"><div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3">\n\
<label for="add-session">Add session:</label><input type="text" class="form-control book-control" name="CourseBatche[ClassVenue][' + venueCounter + '][no_of_session][]" id="no_of_session_venue_' + venueCounter + '_batch_0" onchange="return dateSessionValue(this.id);" onkeyup="return dateSessionValue(this.id);" onkeypress="return isNumberKey(event);" placeholder="0"  maxlength="2">\n\
<div class="errorMessage" id="error_course_no_of_session_venue_' + venueCounter + '_batch_0" style="display:none">No of session cannot be blank.</div></div><div class="col-lg-9 col-md-9 col-sm-9 column9"></div>\n\
</div></div><div class="venue_' + venueCounter + '_batch_0_dateSession " style="display: none;">  </div><div class="class-struct"> <h4>class structure:</h4>\n\
<div id="venue_' + venueCounter + '_batch_0_classStructures"> <div class="form-group"><div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3"><label for="ClassStructures_start_time">Start Time</label>\n\
<div class="input-append bootstrap-timepicker time-sin input-group input-group-lg"><input name="ClassStructures[ClassVenue][' + venueCounter + '][ClassBatch][0][start_time][]" id="class_venue_' + venueCounter + '_classbatch_0_struct_start_time_0" type="text" class="add-on book-control time-sin" placeholder="0" maxlength="3" value="0" readonly="readonly"> <span class="input-group-addon">Min</span>\n\
</div></div><div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3"><label for="ClassStructures_end_time">End Time</label><div class="input-append bootstrap-timepicker time-sin time-sin input-group input-group-lg">\n\
<input type="hidden" name="addclassStructure" id="class_venue_' + venueCounter + '_classbatch_0_struct_struct_count_0" value="0" class="class_venue_' + venueCounter + '_classbatch_0_startDatecount">\n\
<input onkeypress="return isNumberKey(event)" name="ClassStructures[ClassVenue][' + venueCounter + '][ClassBatch][0][end_time][]" id="class_venue_' + venueCounter + '_classbatch_0_struct_end_time_0" type="text" class="add-on book-control time-sin" maxlength="2" onblur="addValueInclassStructureStartTime(this.id)"><span class="input-group-addon">Min</span>\n\
</div></div></div><div class="form-group"><div class="col-lg-12 col-md-12 col-sm-12 column12 course-pdlr">\n\
<label for="ClassStructures_description">Description</label><textarea name="ClassStructures[ClassVenue][' + venueCounter + '][ClassBatch][0][description][]" id="class_venue_' + venueCounter + '_classbatch_0_struct_struct_description_0" class="form-control book-control"> </textarea>\n\
</div></div></div><div class="clearfix"></div><div class="form-group"><div class="col-lg-3 col-md-3 col-sm-3 column3 add-struct course-pdl"><a href="javascript:void(0)" class="class_venue_' + venueCounter + '_classbatch_0_add_structure" id="class_venue_' + venueCounter + '_classbatch_0_struct_add_count_0" onclick="addclassStructures(this.id);">Add Structures</a></div></div></div></div></div></div> \n\
</div></div></div><div class="row batch-row adding-el"><div class="col-lg-12 column12 course-pdr"><a href="javascript:void(0)" class="btn-green" id="venue_' + venueCounter + '_batch_0" onclick="addBatch(this.id);">Add Batch</a></div></div></div><div class="clearfix"></div> ');
     $("#" + venueId).attr('id', 'venue_' + venueCounter);
}

function reMoveVenue(venueId) {
    array = venueId.split("_");
    $('#venue_count_' + array[2]).remove();
    $('.add_venue_course_show_hide_' + array[2]).remove();
    createdVenueCount();
    $('.add_venue_course_show_hide_0').addClass('active');
    $('.venue_course_show_hide_0').show();
}

function addBatch(batchVenueId) {
    var array = batchVenueId.split("_");
    batchCounter = parseInt(array[3]) + 1;
    venueIndex = array[1];
    $(".contenttoggleClass").hide();
    $(".uncollapse").hide();
    $('.addbatch_venue_' + venueIndex + '_batch').append('<div id="venue_count' + venueIndex + '_batch_' + batchCounter + '"><div class="batch-second">\n\
<div class="details-collapse clearfix" id="venue_count' + venueIndex + '_batchShowToggle_' + batchCounter + '" onclick="showhideBatch(this.id);">\n\
<h3><span>batch <span class="createdVenueBatchCount create_venue_' + venueIndex + '_batchcounter"id="create_venue_' + venueIndex + '_batch_counter_' + batchCounter + '">1</span></span> <span class="buttom-exp pull-right"><em class="sprite dw-arrow"></em></span> </h3>\n\
</div><div class="clearfix contenttoggleClass venue_count' + venueIndex + '_batchShowToggle_' + batchCounter + '""><div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3">\n\
<label for="CourseBatche_date_from" class="required">Start Date<span class="required">*</span></label> <input type="hidden" name="batchIndex[' + venueIndex + '][]" value="' + batchCounter + '">\n\
<input id="course_venue_' + venueIndex + '_batch_start_date_' + batchCounter + '" name="CourseBatche[ClassVenue][' + venueIndex + '][date_from][]" type="text" class="requiredfield hasDatepicker span2 form-control book-control" onkeyup="hasDatepicker(this.id);" onblur="checkValueEmpty(this.id)" onclick="hasDatepicker(this.id);" onpaste="return false;" onchange="checkDate(this.id)">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_start_date_' + batchCounter + '" style="display:none">Start date cannot be blank.</div></div>\n\
<div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3"><label for="CourseBatche_date_to" class="required">End Date <span class="required">*</span></label>\n\
<input name="CourseBatche[ClassVenue][' + venueIndex + '][date_to][]" id="course_venue_' + venueIndex + '_batch_end_date_' + batchCounter + '" type="text" class="hasDatepicker requiredfield span2 form-control book-control" onkeyup="hasDatepicker(this.id)" onclick="hasDatepicker(this.id)" onpaste="return false;" onblur="checkValueEmpty(this.id)" onchange="checkDate(this.id)">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_end_date_' + batchCounter + '" style="display:none">End date cannot be blank.</div>\n\
<div class="errorMessage" id="enddate_course_venue_' + venueIndex + '_batch_end_date_' + batchCounter + '"></div></div><div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3">\n\
<label for="CourseBatche_price" class="required">Price <span class="required">*</span></label><input name="CourseBatche[ClassVenue][' + venueIndex + '][price][]" id="course_venue_' + venueIndex + '_batch_price_' + batchCounter + '" type="text" onkeypress="return isNumberKey(event)" class="requiredfield span2 form-control book-control" onblur="checkValueEmpty(this.id)">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_price_' + batchCounter + '" style="display:none">Price cannot be blank.</div></div>\n\
<div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3"><label for="CourseBatche_seats" class="required">Seats <span class="required">*</span></label>\n\
<input name="CourseBatche[ClassVenue][' + venueIndex + '][seats][]" id="course_venue_' + venueIndex + '_batch_seats_' + batchCounter + '" type="text" onkeypress="return isNumberKey(event)" class="requiredfield span2 form-control book-control" onblur="checkValueEmpty(this.id)">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_seats_' + batchCounter + '" style="display:none">Seats cannot be blank.</div></div>\n\
<div class="batch-disc"><h4>Batch discounts:</h4><div id="venue_' + venueIndex + '_batch_' + batchCounter + '_earlydiscount"></div><div class="form-group">\n\
<div class="col-lg-3 col-md-3 col-sm-3 column3 add-disc course-pdl"><a href="javascript:void(0)" id="venue_' + venueIndex + '_batch_' + batchCounter + '_earlydiscount_0" onclick="addEarlyDiscount(this.id);">+ Add Early Discounts</a></div></div>\n\
<div id="venue_' + venueIndex + '_batch_' + batchCounter + '_groupdiscount"></div><div class="form-group"><div class="col-lg-3 col-md-3 col-sm-3 column3 add-disc course-pdl">\n\
<a href="javascript:void(0)" id="venue_' + venueIndex + '_batch_' + batchCounter + '_groupdiscount_0" onclick="addGroupDiscount(this.id);">+ Add Group Discounts</a></div></div>\n\
<div class="row"><div class="col-lg-12 col-md-12 col-sm-12 course-pdl column12"><div class="my-radio"><input type="radio" class="venue_' + venueIndex + '_batch_' + batchCounter + '_fancyRadio"  id="venue_' + venueIndex + '_batch_' + batchCounter + '_daySession_show_hide" name="days_venue_' + venueIndex + '_batch_' + batchCounter + '" checked="checked" onclick="showDateSessionAndDaySesion(this.id)" ><label for="venue_' + venueIndex + '_batch_' + batchCounter + '_daySession_show_hide">Days of the week</label>\n\
<input type="radio" class="venue_' + venueIndex + '_batch_' + batchCounter + '_fancyRadio"  id="venue_' + venueIndex + '_batch_' + batchCounter + '_dateSession" name="days_venue_' + venueIndex + '_batch_' + batchCounter + '" onclick="showDateSessionAndDaySesion(this.id)"><label for="venue_' + venueIndex + '_batch_' + batchCounter + '_dateSession">Number of Sessions</label>\n\
</div></div></div></div><div class="batch-disc"> <h4>Batch Session:</h4><div class="venue_' + venueIndex + '_batch_' + batchCounter + '_daySession_show_hide"><div class="form-group"><div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3">\n\
<label for="course_venue_0_batch_0_daySession_schedule_id_0">Select day</label><span class="class-arrow12"></span><select name="CourseBatcheDaySession[CourseBatche][' + batchCounter + '][ClassVenue][' + venueIndex + '][schedule_id][]" id="course_venue_' + venueIndex + '_batch_' + batchCounter + '_daySession_schedule_id_0" class="form-control book-control requiredfield">\n\
<option value="">Select Day</option><option value="5">Monday</option><option value="6">Tuesday</option><option value="7">Wednesday</option>\n\
<option value="8">Thursday</option><option value="9">Friday</option><option value="10">Saturday</option><option value="11">Sunday</option></select>\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_' + batchCounter + '_daySession_schedule_id_0" style="display:none">Schedule cannot be blank.</div></div>\n\
<div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3"><label for="b-stime">Start time:</label><div class="input-append bootstrap-timepicker time-sin">\n\
<input  name="CourseBatcheDaySession[CourseBatche][' + batchCounter + '][ClassVenue][' + venueIndex + '][time_from][]" id="course_venue_' + venueIndex + '_batch_' + batchCounter + '_daySession_time_from_0" type="text"  class="hastimePicker requiredfield add-on book-control time-sin" onclick="hastimePicker(this.id)" onpaste="return false;" onblur="checkValueEmpty(this.id)" onchange="timeCheck(this.id)"> \n\
<div class="errorMessage" id="error_venue_' + venueIndex + '_batch_' + batchCounter + '_daySession_time_from_0" style="display:none">Start time cannot be blank.</div> </div></div><div class="col-lg-6 col-md-6 col-sm-6 course-pdr column6"><div class="col-lg-7 col-md-7 col-sm-7 column6">\n\
<label for="b-etime">End time:</label><div class="input-append bootstrap-timepicker time-sin"><input name="CourseBatcheDaySession[CourseBatche][' + batchCounter + '][ClassVenue][' + venueIndex + '][time_to][]" id="course_venue_' + venueIndex + '_batch_' + batchCounter + '_daySession_time_to_0" class="hastimePicker requiredfield  add-on book-control time-sin" onclick="hastimePicker(this.id)" onpaste="return false;" onblur="checkValueEmpty(this.id)" type="text"  size="10" onchange="timeCheck(this.id)">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_' + batchCounter + '_daySession_time_to_0" style="display:none">End time cannot be blank.</div>\n\
<div class="errorMessage" id="endTime_course_venue_' + venueIndex + '_batch_' + batchCounter + '_daySession_time_to_0"></div></div></div>\n\
<div class="col-lg-5 col-md-5 col-sm-5 column5"><div class="batch-flexible"><input type="checkbox" class="fancyCheckBox" value="1" id="course_venue_' + venueIndex + '_batch_' + batchCounter + '_daySession_is_flexible_0" onclick="datedaySesionisFlexble(this.id)" name="CourseBatcheDaySessions[CourseBatche][' + batchCounter + '][ClassVenue][' + venueIndex + '][is_flexible][]" >\n\
<label for="course_venue_' + venueIndex + '_batch_' + batchCounter + '_daySession_is_flexible_0"> Flexible </label><input type="hidden" name="CourseBatcheDaySession[CourseBatche][' + batchCounter + '][ClassVenue][' + venueIndex + '][is_flexiblevalue][]" value="0" id="course_venue_' + venueIndex + '_batch_' + batchCounter + '_daySession_is_flexiblevalue_0"/></div> </div></div></div></div>\n\
<div class="venue_' + venueIndex + '_batch_' + batchCounter + '_daySession"></div><div class="venue_' + venueIndex + '_batch_' + batchCounter + '_daySession_addSesion"><div class="form-group"><div class="col-lg-3 col-md-3 col-sm-3 add-disc course-pdl column3">\n\
<a  href="javascript:void(0);" onclick="addDaySession(this.id);" id="venue_' + venueIndex + '_batch_' + batchCounter + '_daySession_0">+Add More</a></div></div></div><div class="venue_' + venueIndex + '_batch_' + batchCounter + '_dateNoSession" style="display: none;">\n\
 <div class="row"> <div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3"><label for="add-session">Add session:</label><input type="text" class="form-control book-control" name="CourseBatche[ClassVenue][' + venueIndex + '][no_of_session][]" id="no_of_session_venue_' + venueIndex + '_batch_' + batchCounter + '" onchange="return dateSessionValue(this.id);" onkeyup="return dateSessionValue(this.id);" onkeypress="return isNumberKey(event);" placeholder="0"  maxlength="2">\n\
<div class="errorMessage" id="error_course_no_of_session_venue_' + venueIndex + '_batch_' + batchCounter + '" style="display:none">No of session cannot be blank.</div>\n\
</div><div class="col-lg-9 col-md-9 col-sm-9 column9"></div></div></div><div class="venue_' + venueIndex + '_batch_' + batchCounter + '_dateSession" style="display: none;"></div>\n\
</div><div class="class-struct"> <h4>class structure:</h4><div id="venue_' + venueIndex + '_batch_' + batchCounter + '_classStructures">\n\
<div class="form-group"><div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3"><label for="ClassStructures_start_time">Start Time</label>\n\
<div class="input-append bootstrap-timepicker time-sin input-group input-group-lg"><input name="ClassStructures[ClassVenue][' + venueIndex + '][ClassBatch][' + batchCounter + '][start_time][]" id="class_venue_' + venueIndex + '_batch_' + batchCounter + '_struct_start_time_0" type="text" class="add-on book-control time-sin" placeholder="0" maxlength="3" value="0" readonly="readonly"><span class="input-group-addon">Min</span></div></div>\n\
<div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3"><label for="ClassStructures_end_time">End Time</label><div class="input-append bootstrap-timepicker time-sin time-sin input-group input-group-lg">\n\
<input type="hidden" name="addclassStructure" id="class_venue_' + venueIndex + '_classbatch_' + batchCounter + '_struct_struct_count_0" value="0" class="class_venue_' + venueIndex + '_classbatch_' + batchCounter + '_startDatecount">\n\
<input onkeypress="return isNumberKey(event)" name="ClassStructures[ClassVenue][' + venueIndex + '][ClassBatch][' + batchCounter + '][end_time][]" id="class_venue_' + venueIndex + '_classbatch_' + batchCounter + '_struct_end_time_0" type="text" class="fadd-on book-control time-sin" maxlength="2" onblur="addValueInclassStructureStartTime(this.id)"> <span class="input-group-addon">Min</span></div></div></div>\n\
 <div class="form-group"> <div class="col-lg-12 col-md-12 col-sm-12 column12 course-pdlr"><label for="ClassStructures_description">Description</label>\n\
<textarea name="ClassStructures[ClassVenue][' + venueIndex + '][ClassBatch][' + batchCounter + '][description][]" class="form-control book-control" id="class_venue_' + venueIndex + '_classbatch_' + batchCounter + '_struct_struct_description_0"> </textarea>\n\
 </div> </div></div><div class="clearfix"></div><div class="form-group"><div class="col-lg-3 col-md-3 col-sm-3 column3 add-struct course-pdl"><a href="javascript:void(0)" class="btn-green class_venue_' + venueIndex + '_classbatch_' + batchCounter + '_add_structure" id="class_venue_' + venueIndex + '_classbatch_' + batchCounter + '_struct_add_count_0" onclick="addclassStructures(this.id);">Add Structures</a>\n\
 </div></div></div><div class="row batch-row adding-el"><div class="col-lg-12 column12 course-pdr"><a href="javascript:void(0)" id="venue_remove_' + venueIndex + '_batch_' + batchCounter + '" onclick="reMoveBatch(this.id);">-Remove Batch</a>\n\
</div></div></div><div class="clearfix"></div>');
    $("#" + batchVenueId).attr('id', 'venue_' + venueIndex + '_batch_' + batchCounter);
    createdBatchCount('create_venue_' + venueIndex + '_batchcounter');
    var elementClick = '#venue_count' + venueIndex + '_batch_' + batchCounter
    var destination = $(elementClick).offset().top;
    $("html:not(:animated),body:not(:animated)").animate({scrollTop: destination}, function() {
        window.location.hash = elementClick
    });
}


function reMoveBatch(batchId) {
    var array = batchId.split("_");
    $('#venue_count' + array[2] + '_batch_' + array[4]).remove();
    createdBatchCount('create_venue_' + array[2] + '_batchcounter');
}

function addEarlyDiscount(earlyDiscountId) {
    var array = earlyDiscountId.split("_");
    earlyCounter = parseInt(array[5]) + 1;
    venueIndex = array[1];
    batchIndex = array[3];
    $('#venue_' + venueIndex + '_batch_' + batchIndex + '_earlydiscount').append('<div id="venue_' + venueIndex + '_batch_' + batchIndex + '_earlyCount_' + earlyCounter + '">\n\
<div class="col-lg-3 col-md-3 col-sm-3 column4 course-pdl"><input onblur="checkValueEmpty(this.id);" onchange="enableDisableEarlyBirdTextField(this.id);"  name="ClassEarlyDiscount[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][discount_price][]" id="course_venue_' + venueIndex + '_batch_' + batchIndex + '_early_discount_price_' + earlyCounter + '" type="text" placeholder="Discount Price" onkeypress="return isNumberKey(event)"   class="requiredfield span2 form-control book-control">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_' + batchIndex + '_early_discount_price_' + earlyCounter + '" style="display:none">Discount price is required.</div></div>\n\
<div class="col-lg-3 col-md-3 col-sm-3 column4"><input onblur="checkValueEmpty(this.id);" onchange="enableDisableEarlyBirdTextField(this.id);"  name="ClassEarlyDiscount[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][in_percentage][]" id="course_venue_' + venueIndex + '_batch_' + batchIndex + '_early_in_percentage_' + earlyCounter + '" type="text" placeholder="In Percentage" onkeypress="return isNumberKey(event)"   class="requiredfield span2 form-control book-control">\n\
<div class="errorMessage" id="error_class_venue_' + venueIndex + '_batch_' + batchIndex + '_early_in_percentage_' + earlyCounter + '" style="display:none">Percentage is required.</div></div>\n\
<div class="col-lg-3 col-md-3 col-sm-3 course-pdr column4"><input  name="ClassEarlyDiscount[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][valid_to][]" id="course_venue_' + venueIndex + '_batch_' + batchIndex + '_early_valid_to_' + earlyCounter + '" class="hasDatepicker requiredfield  span2 form-control book-control" onkeyup="hasDatepicker(this.id);"  onclick="hasDatepicker(this.id);" onpaste="return false;" onblur="checkValueEmpty(this.id)" type="text" placeholder="Valid To" readonly="readonly" size="10">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_' + batchIndex + '_early_valid_to_' + earlyCounter + '" style="display:none">Valid to is required.</div></div>\n\
<div class="col-lg-3 col-md-3 col-sm-3 course-pdr column4"><a href="javascript:void(0)" id="venue_' + venueIndex + '_batch_' + batchIndex + '_earlyRemove_' + earlyCounter + '" onclick="removeEarlyDiscount(this.id);">-Remove</a></div>\n\
<div class="gap1"></div></div>');
    $("#" + earlyDiscountId).attr('id', 'venue_' + venueIndex + '_batch_' + batchIndex + '_earlydiscount_' + earlyCounter + '');
}

function removeEarlyDiscount(removeEarly) {
    var array = removeEarly.split("_");
    $('#venue_' + array[1] + '_batch_' + array[3] + '_earlyCount_' + array[5] + '').remove();
}

function addGroupDiscount(groupDiscountId) {
    var array = groupDiscountId.split("_");
    groupCounter = parseInt(array[5]) + 1;
    venueIndex = array[1];
    batchIndex = array[3];
    $('#venue_' + venueIndex + '_batch_' + batchIndex + '_groupdiscount').append('<div id="venue_' + venueIndex + '_batch_' + batchIndex + '_groupCount_' + groupCounter + '">\n\
<div class="col-lg-3 col-md-3 col-sm-3 column4 course-pdl"><input  onchange="enableDisableGroupDiscountTextField(this.id);"  name="GroupDiscount[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][discount_amount][]" id="course_venue_' + venueIndex + '_batch_' + batchIndex + '_group_discount_amount_' + groupCounter + '" onblur="checkValueEmpty(this.id);" type="text" placeholder="Discount Amount" onkeypress="return isNumberKey(event)" class="requiredfield span2 form-control book-control">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_' + batchIndex + '_group_discount_amount_' + groupCounter + '" style="display:none">Discount is required.</div></div>\n\
<div class="col-lg-3 col-md-3 col-sm-3 column4"><input  onchange="enableDisableGroupDiscountTextField(this.id);" name="GroupDiscount[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][discount_in_percentage][]" id="course_venue_' + venueIndex + '_batch_' + batchIndex + '_group_in_percentage_' + groupCounter + '" onblur="checkValueEmpty(this.id);" type="text" placeholder="Discount in percentage" onkeypress="return isNumberKey(event)" class="requiredfield span2 form-control book-control">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_' + batchIndex + '_group_in_percentage_' + groupCounter + '" style="display:none">Amount is required.</div></div>\n\
<div class="col-lg-3 col-md-3 col-sm-3 column4 course-pdl"><input  name="GroupDiscount[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][group_size][]" id="course_venue_' + venueIndex + '_batch_' + batchIndex + '_group_size_' + groupCounter + '" type="text" placeholder="Group Size" onblur="checkValueEmpty(this.id)" onkeypress="return isNumberKey(event)" class="requiredfield span2 form-control book-control">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_' + batchIndex + '_group_size_' + groupCounter + '" style="display:none">Group Size is required.</div></div>\n\
<div class="col-lg-3 col-md-3 col-sm-3 column4 course-pdl"><a href="javascript:void(0)" id="venue_' + venueIndex + '_batch_' + batchIndex + '_groupRemove_' + groupCounter + '" onclick="removeGroupDiscount(this.id);">-Remove</a></div>\n\
<div class="gap1"></div></div>');
    $("#" + groupDiscountId).attr('id', 'venue_' + venueIndex + '_batch_' + batchIndex + '_groupdiscount_' + groupCounter + '');
}

function removeGroupDiscount(removeGroup) {
    var array = removeGroup.split("_");
    $('#venue_' + array[1] + '_batch_' + array[3] + '_groupCount_' + array[5] + '').remove();
}
function enableDisableEarlyBirdTextField(id) {
    var array = id.split("_");
    var inPericentageId = 'course_venue_' + array[2] + '_batch_' + array[4] + '_early_discount_price_' + array[8] + '';
    var inDiscountPriceId = 'course_venue_' + array[2] + '_batch_' + array[4] + '_early_in_percentage_' + array[8] + '';
    var inDiscountPriceVal = $("#" + inDiscountPriceId).val();
    var inPericentageVal = $("#" + inPericentageId).val();
    if (inDiscountPriceId == id && inDiscountPriceVal != '')
    {
        $("#" + inPericentageId).attr("readonly", "readonly");
        $("#" + inPericentageId).removeClass("requiredfield");
        $("#" + inPericentageId).removeAttr('style');
    }
    else if (inPericentageId == id && inPericentageVal != '') {
        $("#" + inDiscountPriceId).attr("readonly", "readonly");
        $("#" + inDiscountPriceId).removeClass("requiredfield");
        $("#" + inDiscountPriceId).removeAttr('style');
    }
    else if (inDiscountPriceVal == '' && inPericentageVal == '') {
        $("#" + inDiscountPriceId).removeAttr("readonly");
        $("#" + inPericentageId).removeAttr("readonly");
        $("#" + inPericentageId).addClass("requiredfield");
        $("#" + inDiscountPriceId).addClass("requiredfield");
    }

}

function enableDisableGroupDiscountTextField(id) {
    var array = id.split("_");
    var inPericentageId = 'course_venue_' + array[2] + '_batch_' + array[4] + '_group_in_percentage_' + array[8] + '';
    var inDiscountPriceId = 'course_venue_' + array[2] + '_batch_' + array[4] + '_group_discount_amount_' + array[8] + '';
    var inDiscountPriceVal = $("#" + inDiscountPriceId).val();
    var inPericentageVal = $("#" + inPericentageId).val();
    if (inDiscountPriceId == id && inDiscountPriceVal != '')
    {
        $("#" + inPericentageId).attr("readonly", "readonly");
        $("#" + inPericentageId).removeClass("requiredfield");
        $("#" + inPericentageId).removeAttr('style');
    }
    else if (inPericentageId == id && inPericentageVal != '') {
        $("#" + inDiscountPriceId).attr("readonly", "readonly");
        $("#" + inDiscountPriceId).removeClass("requiredfield");
        $("#" + inDiscountPriceId).removeAttr('style');
    }
    else if (inDiscountPriceVal == '' && inPericentageVal == '') {
        $("#" + inDiscountPriceId).removeAttr("readonly");
        $("#" + inPericentageId).removeAttr("readonly");
        $("#" + inPericentageId).addClass("requiredfield");
        $("#" + inDiscountPriceId).addClass("requiredfield");
    }
}

function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    return true;
}

function hasDatepicker(id) {  
    $("#" + id).attr('readonly', 'readonly');
    $("#" + id).removeClass('hasDatepicker').datepicker({
        changeMonth: true,
        changeYear: true,
        stepMonths: 12,
        showButtonPanel: false,
        beforeShowDay: NotBeforeToday,
        dateFormat: 'yy-mm-dd',
        yearRange: "-0:+15"
    }).focus();
}

function NotBeforeToday(date) {
    var now = new Date();//this gets the current date and time
    if (date.getFullYear() == now.getFullYear() && date.getMonth() == now.getMonth() && date.getDate() > now.getDate())
        return [true];
    if (date.getFullYear() >= now.getFullYear() && date.getMonth() > now.getMonth())
        return [true];
    if (date.getFullYear() > now.getFullYear())
        return [true];
    return [false];
}

function hastimePicker(id) {
    $("#" + id).attr('readonly', 'readonly');
    $("#" + id).removeClass('hasDatepicker').timepicker({
        minuteGrid: 10,
        timeFormat: 'hh:mm tt',
        ampm: true
    });
}

function addclassStructures(id) {
    var array = id.split("_");
    var startTimeVal = $('#class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_end_time_' + array[8] + '').val();
    var classStructures = $('#class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_struct_count_' + array[8] + '').val(array[8]);
    var classStructures = parseInt(array[8]) + 1;
    $('#class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_add_count_' + array[8] + '').attr('id', 'class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_add_count_' + classStructures + '');
    $('#venue_' + array[2] + '_batch_' + array[4] + '_classStructures').append('<div class="clearfix"></div><div class="classStructureControl" id="remove_class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_remove_count_' + classStructures + '" >\n\
<div class="form-group"><div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3"><label for="ClassStructures_start_time">Start Time</label> <div class="input-append bootstrap-timepicker time-sin input-group input-group-lg">\n\
<input class="add-on book-control time-sin"  onkeypress="return isNumberKey(event)" maxlength="3" name="ClassStructures[ClassVenue][' + array[2] + '][ClassBatch][' + array[4] + '][start_time][]" id="class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_start_time_' + classStructures + '" type="text" readonly="readonly" maxlength="2" value=' + startTimeVal + ' >\n\
<span class="input-group-addon">Min</span></div> </div><div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3"> <label for="ClassStructures_end_time">End Time</label><div class="input-append bootstrap-timepicker time-sin time-sin input-group input-group-lg">\n\
<input class="add-on book-control time-sin enddateCount" onkeypress="return isNumberKey(event)" name="ClassStructures[ClassVenue][' + array[2] + '][ClassBatch][' + array[4] + '][end_time][]" maxlength="2" id="class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_end_time_' + classStructures + '" type="text" onblur="addValueInclassStructureStartTime(this.id);" >\n\
<span class="input-group-addon">Min</span></div></div> </div><div class="form-group">  <div class="col-lg-12 col-md-12 col-sm-12 column12 course-pdlr">\n\
<label for="ClassStructures_description">Description</label><textarea class="form-control book-control"  name="ClassStructures[ClassVenue][' + array[2] + '][ClassBatch][' + array[4] + '][description][]" id="class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_struct_description_' + classStructures + '" ></textarea>\n\
<input type="hidden" class="class_venue_' + array[2] + '_classbatch_' + array[4] + '_startDatecount" name="addclassStructure" class="addclassStructurecount" id="class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_struct_count_' + classStructures + '" value="' + classStructures + '">\n\
</div></div><div class="form-group"><div class="col-lg-3 col-md-3 col-sm-3 column3 add-struct course-pdl"><a href="javascript:void(0)" class="class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_remove_count_' + classStructures + '" id="class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_remove_count_' + classStructures + '" onclick="removeclassStructures(this.id);">-Remove</a>\n\
</div></div></div>');
}

function addValueInclassStructureStartTime(id) {
    var array = id.split("_");
    var endTimeId = parseInt(array[8]) + 1;
    var startTimeVal = $('#class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_start_time_' + endTimeId + '').val($("#" + id).val());
}

function removeclassStructures(structid) {
    var i = 0;
    var arrayVal = structid.split("_");
    $("div #remove_" + structid).remove();
    $(".class_venue_" + arrayVal[2] + "_classbatch_" + arrayVal[4] + "_startDatecount").each(function() {
        array = this.id.split("_");
        $("#" + this.id).attr('id', 'class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_struct_count_' + i).val(i);
        $('#class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_start_time_' + array[8] + '').attr('id', 'class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_start_time_' + i);
        $('#class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_end_time_' + array[8] + '').attr('id', 'class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_end_time_' + i);
        $('#class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_struct_description_' + array[8] + '').attr('id', 'class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_struct_description_' + i);
        $('#remove_class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_add_count_' + array[8] + '').attr('id', 'remove_class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_add_count_' + i);
        i++;
    });
    var totalCount = parseInt(i) - 1;
    $('.class_venue_' + array[2] + '_classbatch_' + array[4] + '_add_structure').attr('id', 'class_venue_' + array[2] + '_classbatch_' + array[4] + '_struct_add_count_' + totalCount);

}
function addSesionOnRadioChange(sessionId) {
    var array = sessionId.split("_");
    batchIndex = parseInt(array[3]);
    venueIndex = array[1];
    $('Div .venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_show_hide').html('<div class="form-group">\n\
 <div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3"> <label for="course_venue_0_batch_0_daySession_schedule_id_0">Select day</label>\n\
<span class="class-arrow12"></span><select name="CourseBatcheDaySession[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][schedule_id][]" id="course_venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_schedule_id_0" class="form-control book-control requiredfield course_venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_schedule_id_0">\n\
<option value="">Select Day</option><option value="5">Monday</option><option value="6">Tuesday</option><option value="7">Wednesday</option>\n\<option value="8">Thursday</option><option value="9">Friday</option><option value="10">Saturday</option><option value="11">Sunday</option></select>\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_schedule_id_0" style="display:none">Schedule cannot be blank.</div> </div>\n\
<div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3"><label for="b-stime">Start time:</label><div class="input-append bootstrap-timepicker time-sin">\n\
<input class="hastimePicker requiredfield  add-on book-control time-sin" name="CourseBatcheDaySession[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][time_from][]" id="course_venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_time_from_0" type="text" placeholder="Start Time" onkeyup="hastimePicker(this.id);" onclick="hastimePicker(this.id);"  onpaste="return false;" onchange="timeCheck(this.id);">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_time_from_0" style="display:none">Start time cannot be blank.</div></div></div>\n\
<div class="col-lg-6 col-md-6 col-sm-6 course-pdr column6"><div class="col-lg-7 col-md-7 col-sm-7 column6"><label for="b-etime">End time:</label>\n\
<div class="input-append bootstrap-timepicker time-sin"><input class="hastimePicker requiredfield  add-on book-control time-sin" name="CourseBatcheDaySession[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][time_to][]" id="course_venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_time_to_0" type="text" placeholder="End Time" onkeyup="hastimePicker(this.id);" onclick="hastimePicker(this.id);"  onpaste="return false;" onchange="timeCheck(this.id);">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_time_to_0" style="display:none">End time cannot be blank.</div>\n\
 <div class="errorMessage" id="endTime_course_venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_time_to_0"></div></div></div>\n\
<div class="col-lg-5 col-md-5 col-sm-5 column5"> <div class="batch-flexible"><input type="checkbox" class="isdaySesionFlexble" value="1" id="course_venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_is_flexible_0" onclick="datedaySesionisFlexble(this.id)" name="CourseBatcheDaySessions[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][is_flexible][]" ><label for="course_venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_is_flexible_0"> Flexible </label>\n\
<input type="hidden" name="CourseBatcheDaySession[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][is_flexiblevalue][]" value="0" id="course_venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_is_flexiblevalue_0"/></div> </div> \n\
</div>');
}


function addDaySession(sessionId) {
    var array = sessionId.split("_");
    var addDayCounter = parseInt(array[5]);
    var addDaySessionCounter = parseInt(addDayCounter) + 1;
    batchIndex = parseInt(array[3]);
    venueIndex = array[1];
    $('Div .venue_' + venueIndex + '_batch_' + batchIndex + '_daySession').append('<div class="venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_' + addDaySessionCounter + '">\n\
<div class="form-group"><div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3"><span class="class-arrow12"></span><select name="CourseBatcheDaySession[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][schedule_id][]" id="course_venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_schedule_id_' + addDaySessionCounter + '" class=" form-control book-control requiredfield course_venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_schedule_id_' + addDaySessionCounter + '">\n\
<option value="">Select Day</option><option value="5">Monday</option><option value="6">Tuesday</option><option value="7">Wednesday</option>\n\<option value="8">Thursday</option><option value="9">Friday</option><option value="10">Saturday</option><option value="11">Sunday</option></select>\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_schedule_id_' + addDaySessionCounter + '" style="display:none">Schedule cannot be blank.</div></div>\n\
<div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3"><div class="input-append bootstrap-timepicker time-sin"><input class="hastimePicker requiredfield add-on book-control time-sin" name="CourseBatcheDaySession[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][time_from][]" id="course_venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_time_from_' + addDaySessionCounter + '" type="text" placeholder="Start Time" onkeyup="hastimePicker(this.id);" onclick="hastimePicker(this.id);"  onpaste="return false;" onchange="timeCheck(this.id);">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_time_from_' + addDaySessionCounter + '" style="display:none">Start time cannot be blank.</div></div></div>\n\
<div class="col-lg-6 col-md-6 col-sm-6 course-pdr column6"><div class="col-lg-7 col-md-7 col-sm-7 column6"><div class="input-append bootstrap-timepicker time-sin"><input class="hastimePicker requiredfield  add-on book-control time-sin" name="CourseBatcheDaySession[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][time_to][]" id="course_venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_time_to_' + addDaySessionCounter + '" type="text" placeholder="End Time" onkeyup="hastimePicker(this.id);" onclick="hastimePicker(this.id);"  onpaste="return false;" onchange="timeCheck(this.id);">\n\
<div class="errorMessage" id="error_course_venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_time_to_' + addDaySessionCounter + '" style="display:none">End time cannot be blank.</div>\n\
 <div class="errorMessage" id="endTime_course_venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_time_to_' + addDaySessionCounter + '"></div></div></div><div class="col-lg-5 col-md-5 col-sm-5 column5">\n\
<div class="batch-flexible"><input type="checkbox" class="fancyCheckBox" name="CourseBatcheDaySessions[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][is_flexible][]" id="course_venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_is_flexible_' + addDaySessionCounter + '" onclick="datedaySesionisFlexble(this.id)">\n\
<label for="course_venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_is_flexible_' + addDaySessionCounter + '"> Flexible </label>\n\
<input type="hidden" name="CourseBatcheDaySession[CourseBatche][' + batchIndex + '][ClassVenue][' + venueIndex + '][is_flexiblevalue][]" value="0" id="venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_is_flexiblevalue_' + addDaySessionCounter + '"/></div>\n\
<a class="link-remove" id="remove_venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_' + addDaySessionCounter + '" onclick="removeDaySession(this.id);"><span>Remove</span></a></div></div>  </div></div> \n\
');
    $("#" + sessionId).attr('id', 'venue_' + venueIndex + '_batch_' + batchIndex + '_daySession_' + addDaySessionCounter);
}
function removeDaySession(BatchDaySessionId) {
    var array = BatchDaySessionId.split("_");
    $('Div .venue_' + array[2] + '_batch_' + array[4] + '_daySession_' + array[6] + '').remove();
}

function createdVenueCount() {
    var i = 1;
    $('.createdVenueCount').each(function() {
        $("#" + this.id).text(i);
        i++;
    })
}

function checkValueEmpty(id) {
    ($("#" + id).val() != '') ? $("#error_" + id).hide() : $("#error_" + id).show();
}

function createdBatchCount(batchId) {
    var i = 1;
    $('.' + batchId).each(function() {
        $("#" + this.id).text(i);
        i++;
    })
}
function dateSessionValue(id) {
    var dataSessionval = $("#" + id).val();
    var dateSessionhtml = "";
    array = id.split("_");
    if (dataSessionval > '0' && dataSessionval < 40) {
        dateSessionhtml += '<div class="form-group"> <div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3"><label>Start date</label></div>\n\
 <div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3"><label>Start Time</label></div><div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3"><label>End Time</label></div><div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3"></div></div>';
        for (var i = 1; i <= dataSessionval; i++) {
            dateSessionhtml += '<div class="form-group"><div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3">\n\
<input class="form-control book-control requiredfield" onpaste="return false;" onclick="hasDatepicker(this.id)" name="CourseBatcheDateSession[CourseBatche][' + array[6] + '][ClassVenue][' + array[4] + '][date][]" id="course_venue_' + array[4] + '_batch_' + array[6] + '_daySession_date_' + i + '" type="text" placeholder="Date">\n\
<div class="errorMessage" id="error_venue_' + array[4] + '_batch_' + array[6] + '_daySession_date_s' + i + '" style="display:none">Start date cannot be blank.</div></div>\n\
 <div class="col-lg-3 col-md-3 col-sm-3 course-pdl column3"><div class="input-append bootstrap-timepicker time-sin">\n\
<input onblur="checkValueEmpty(this.id);"  name="CourseBatcheDateSession[CourseBatche][' + array[6] + '][ClassVenue][' + array[4] + '][time_from][]" id="course_venue_' + array[4] + '_batch_' + array[6] + '_daySession_time_from_' + i + '" type="text"  onclick="hastimePicker(this.id)" onpaste="return false;" onblur="checkValueEmpty(this.id);" class=" hastimePicker add-on book-control time-sin requiredfield"  onchange="timeCheck(this.id);">\n\
 <div class="errorMessage" id="error_course_venue_' + array[4] + '_batch_' + array[6] + '_daySession_time_from_' + i + '" style="display:none">Start time cannot be blank.</div></div></div>\n\
<div class="col-lg-6 col-md-6 col-sm-6 course-pdr column6"><div class="col-lg-7 col-md-7 col-sm-7 column6"><div class="input-append bootstrap-timepicker time-sin">\n\
<input name="CourseBatcheDateSession[CourseBatche][' + array[6] + '][ClassVenue][' + array[4] + '][time_to][]" id="course_venue_' + array[4] + '_batch_' + array[6] + '_daySession_time_to_' + i + '" onclick="hastimePicker(this.id)" onpaste="return false;" onblur="checkValueEmpty(this.id);" class="requiredfield  hastimePicker add-on book-control time-sin"  type="text"   size="10" value="" onchange="timeCheck(this.id);">\n\
<div class="errorMessage" id="error_course_venue_' + array[4] + '_batch_' + array[6] + '_daySession_time_to_' + i + '" style="display:none">End time cannot be blank.</div>\n\
<div class="errorMessage" id="endTime_course_venue_' + array[4] + '_batch_' + array[6] + '_daySession_time_to_' + i + '"></div></div></div>\n\
<div class="col-lg-5 col-md-5 col-sm-5 column5"><div class="batch-flexible"><input type="checkbox" class="isdaySesionFlexble" value="1" id="course_venue_' + array[4] + '_batch_' + array[6] + '_daySession_is_flexible_' + i + '" onclick="datedaySesionisFlexble(this.id)" name="CourseBatcheDateSessions[CourseBatche][' + array[6] + '][ClassVenue][' + array[4] + '][is_flexible][]" >\n\
<label for="course_venue_' + array[4] + '_batch_' + array[6] + '_daySession_is_flexible_' + i + '"> Flexible </label><input type="hidden" name="CourseBatcheDateSession[CourseBatche][' + array[6] + '][ClassVenue][' + array[4] + '][is_flexiblevalue][]" value="0" id="course_venue_' + array[4] + '_batch_' + array[6] + '_daySession_is_flexiblevalue_' + i + '"/>\n\
 </div>  </div>  </div> ';
        }
        $('.venue_' + array[4] + '_batch_' + array[6] + '_dateSession').show();
        $('.venue_' + array[4] + '_batch_' + array[6] + '_dateSession').html(dateSessionhtml);
    }
}
function timeCheck(id) {
    var array = id.split("_");
    startTime = $("#course_venue_" + array[2] + "_batch_" + array[4] + "_daySession_time_from_" + array[8] + "").val();
    endTime = $("#course_venue_" + array[2] + "_batch_" + array[4] + "_daySession_time_to_" + array[8] + "").val();
    if ((endTime != '') && (startTime != '')) {
        var startTimeArray = startTime.split(" ");
        var endTimeArray = endTime.split(" ");
        var firstValEndTime = endTime.split(":");
        var firstValStartTime = startTime.split(":");
        timeCheckByType(startTimeArray, endTimeArray, firstValStartTime, firstValEndTime, array);
    }

}

function timeCheckByType(startTimeArray, endTimeArray, firstValStartTime, firstValEndTime, array) {
    if ((startTimeArray[1] == endTimeArray[1])) {
        if ((parseInt(firstValStartTime[0]) <= 11) && (parseInt(firstValEndTime[0]) <= 11)) {
            var k = 1;
            if ((parseInt(firstValStartTime[0]) == parseInt(firstValEndTime[0])) && (parseInt(firstValStartTime[1]) >= parseInt(firstValEndTime[1]))) {
                $("#course_venue_" + array[2] + "_batch_" + array[4] + "_daySession_time_to_" + array[8]).val('');
                $("#error_course_venue_" + array[2] + "_batch_" + array[4] + "_daySession_time_to_" + array[8]).hide();
                $("#error_course_venue_" + array[2] + "_batch_" + array[4] + "_daySession_time_from_" + array[8]).hide();
                $("#endTime_course_venue_" + array[2] + "_batch_" + array[4] + "_daySession_time_to_" + array[8]).text("End time greater than start time!");
                k = 2;
            }
            if (parseInt(firstValStartTime[0]) > parseInt(firstValEndTime[0])) {
                $("#course_venue_" + array[2] + "_batch_" + array[4] + "_daySession_time_to_" + array[8]).val('');
                $("#error_course_venue_" + array[2] + "_batch_" + array[4] + "_daySession_time_from_" + array[8]).hide();
                $("#endTime_course_venue_" + array[2] + "_batch_" + array[4] + "_daySession_time_to_" + array[8]).text("End time greater than start time!");
                $("#error_course_venue_" + array[2] + "_batch_" + array[4] + "_daySession_time_to_" + array[8]).hide();
                k = 3;
            }
            if (k == 1) {
                $("#endTime_course_venue_" + array[2] + "_batch_" + array[4] + "_daySession_time_to_" + array[8]).text('');
                $("#error_course_venue_" + array[2] + "_batch_" + array[4] + "_daySession_time_from_" + array[8]).hide();
                $("#error_course_venue_" + array[2] + "_batch_" + array[4] + "_daySession_time_to_" + array[8]).hide();
            }
        }
        else if ((parseInt(firstValStartTime[0]) <= 11) && (parseInt(firstValEndTime[0]) >= 11)) {
            if ((parseInt(firstValStartTime[0]) == parseInt(firstValEndTime[0])) && (parseInt(firstValStartTime[1]) >= parseInt(firstValEndTime[1]))) {
                $("#course_venue_" + array[2] + "_batch_" + array[4] + "_daySession_time_to_" + array[8]).val('');
                $("#endTime_course_venue_" + array[2] + "_batch_" + array[4] + "_daySession_time_to_" + array[8]).text("End time greater than start time!");
                $("#error_course_venue_" + array[2] + "_batch_" + array[4] + "_daySession_time_to_" + array[8]).hide();
                $("#error_course_venue_" + array[2] + "_batch_" + array[4] + "_daySession_time_from_" + array[8]).hide();
            }
            if ((parseInt(firstValStartTime[0]) <= 11) && (parseInt(firstValEndTime[0]) >= 11)) {

                $("#course_venue_" + array[2] + "_batch_" + array[4] + "_daySession_time_to_" + array[8]).val('');
                $("#endTime_course_venue_" + array[2] + "_batch_" + array[4] + "_daySession_time_to_" + array[8]).text("End time can not be use 24hours !");
                $("#error_course_venue_" + array[2] + "_batch_" + array[4] + "_daySession_time_to_" + array[8]).hide();
                $("#error_course_venue_" + array[2] + "_batch_" + array[4] + "_daySession_time_from_" + array[8]).hide();
            }

            else {
                $("#endTime_course_venue_" + array[2] + "_batch_" + array[4] + "_daySession_time_to_" + array[8]).text('');
                $("#error_course_venue_" + array[2] + "_batch_" + array[4] + "_daySession_time_to_" + array[8]).hide();
                $("#error_course_venue_" + array[2] + "_batch_" + array[4] + "_daySession_time_from_" + array[8]).hide();
            }
        }

    }
    else {

        $('#endTime_course_venue_' + array[2] + '_batch_end_time_' + array[6]).text('');
        $('#error_course_venue_' + array[2] + '_batch_end_time_' + array[6]).hide();
        $('#error_course_venue_' + array[2] + '_batch_start_time_' + array[6]).hide();
    }


}

function checkDate(id) {
    var array = id.split("_");
    var startDate = $('#course_venue_' + array[2] + '_batch_start_date_' + array[6]).val();
    var endDate = $('#course_venue_' + array[2] + '_batch_end_date_' + array[6]).val();
    if (startDate != '' && endDate != '') {
        var startDateArray = startDate.split(" ");
        var endDateArray = endDate.split(" ");
        if ((startDateArray[0] >= endDateArray[0]) && (startDateArray[1] == endDateArray[1])) {
            $('#course_venue_' + array[2] + '_batch_end_date_' + array[6]).val('');
            $('#enddate_course_venue_' + array[2] + '_batch_end_date_' + array[6]).text("End date greater than start date!");
        }
        if ((startDateArray[0] < endDateArray[0]) && (startDateArray[1] == endDateArray[1])) {
            $('#error_course_venue_' + array[2] + '_batch_end_date_' + array[6]).text('');
            $('#enddate_course_venue_' + array[2] + '_batch_end_date_' + array[6]).text('');
        }
    }
}



function datedaySesionisFlexble(id) {    
    array = id.split("_");
    if ($("#"+id).is(':checked')) {
        $('#course_venue_' + array[2] + '_batch_' + array[4] + '_daySession_time_from_' + array[8]).removeClass("hastimePicker requiredfield");
        $('#course_venue_' + array[2] + '_batch_' + array[4] + '_daySession_time_to_' + array[8]).removeClass("hastimePicker requiredfield");
        $('#course_venue_' + array[2] + '_batch_' + array[4] + '_daySession_time_from_' + array[8]).val('');
        $('#course_venue_' + array[2] + '_batch_' + array[4] + '_daySession_time_to_' + array[8]).val('');
        $('#course_venue_' + array[2] + '_batch_' + array[4] + '_daySession_is_flexiblevalue_' + array[8]).val('1');
    } else {     
        $('#course_venue_' + array[2] + '_batch_' + array[4] + '_daySession_time_from_' + array[8]).addClass("hastimePicker  requiredfield ");
        $('#course_venue_' + array[2] + '_batch_' + array[4] + '_daySession_time_to_' + array[8]).addClass(" hastimePicker requiredfield ");
        $('#course_venue_' + array[2] + '_batch_' + array[4] + '_daySession_is_flexiblevalue_' + array[8]).val('0');
    }
}

function showDateSessionAndDaySesion(id) {
    array = id.split("_");
    if (array[4] != 'dateSession') {
        // $("#venue_"+array[1]+"_batch_"+array[3]+"_dateSession").fancyfields("clean"); 
        $("#no_of_session_venue_" + array[1] + "_batch_" + array[3]).removeClass("requiredfield");
        addSesionOnRadioChange(id);
        $(".venue_" + array[1] + "_batch_" + array[3] + "_daySession_html").html('');
        $(".venue_" + array[1] + "_batch_" + array[3] + "_daySession_addSesion").show();
        $(".venue_" + array[1] + "_batch_" + array[3] + "_dateSession").hide();
        $(".venue_" + array[1] + "_batch_" + array[3] + "_dateNoSession").hide();
    } else {
        $("#no_of_session_venue_" + array[1] + "_batch_" + array[3]).addClass("requiredfield");
        // $("#venue_"+array[1]+"_batch_"+array[3]+"_daySession_show_hide").fancyfields("clean");
        $(".venue_" + array[1] + "_batch_" + array[3] + "_daySession_html").html('');
        $(".venue_" + array[1] + "_batch_" + array[3] + "_daySession_show_hide").html('');
        $(".venue_" + array[1] + "_batch_" + array[3] + "_daySession_addSesion").hide();
        $(".venue_" + array[1] + "_batch_" + array[3] + "_daySession").html('');
        $(".venue_" + array[1] + "_batch_" + array[3] + "_dateNoSession").show();
        $("#no_of_session_venue" + array[1] + "_batch_" + array[3]).val('');
        $(".venue_" + array[1] + "_batch_" + array[3] + "_dateSession").html('');
        $(".venue_" + array[1] + "_batch_" + array[3] + "_dateSession").show();
    }
}
